package com.intel.two.service.community.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.intel.two.common.LayuiPageVo;
import com.intel.two.mapper.community.ProcterMapper;
import com.intel.two.pojo.community.Procter;
import com.intel.two.service.community.ProcterService;
import com.intel.two.vo.community.procterBarVo;
import com.intel.two.vo.community.procterPieVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service("procterService")
public class ProcterServiceImpl implements ProcterService {
    @Autowired
    private ProcterMapper procterMapper;

    @Override
    public LayuiPageVo<Procter> procterPageData(Map<String, Object> params) {

        Integer page = Integer.parseInt(params.get("page")+"");
        Integer limit = Integer.parseInt(params.get("limit")+"");

        PageHelper.startPage(page,limit);
        List<Procter> procters =  procterMapper.selectByParams(params);

        /*分页*/
        PageInfo<Procter> procterPageInfo = new PageInfo<>(procters);
        LayuiPageVo<Procter> procterLayuiPageVo = new LayuiPageVo<>();
        procterLayuiPageVo.setCode(0);
        procterLayuiPageVo.setMsg("学生分页列表数据");
        procterLayuiPageVo.setCount(procterPageInfo.getTotal());
        procterLayuiPageVo.setData(procterPageInfo.getList());
        return procterLayuiPageVo;
    }

    @Override
    public int deleteProcter(Integer procter_id) {
        return procterMapper.deleteProcter(procter_id);
    }

    @Override
    public int deleteProcterAll(Map<String, Object> map) {
        String str = (String) map.get("procter_id");
        String[] strs = str.split("-");
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < strs.length; i++) {
            list.add(Integer.parseInt(strs[i]));
            System.out.println(strs[i]);
        }
        return procterMapper.deleteProcterAll(list);
    }

    @Override
    public int addProcter(Procter procter) {
        return procterMapper.addProcter(procter);
    }

    @Override
    public int updateProcter(Procter procter) {
        return procterMapper.updateProcter(procter);
    }

    @Override
    public List<procterBarVo> procterBar() {
        return procterMapper.procterBar();
    }

    @Override
    public List<procterPieVo> procterPie() {
        return procterMapper.procterPie();
    }
}
